package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.result.Json;
import com.siwei.mes.entity.experiment.ExperimentItemorder;
import com.siwei.mes.service.experiment.ExperimentItemorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账与小票关系相关
 *
 * @author linzi
 * @since 2023-12-19 22:36:28
 */
@Api(value = "试验台账与小票关系")
@RestController
@RequestMapping("experimentItemorder")
public class ExperimentItemorderController {
    @Resource
    private ExperimentItemorderService experimentItemorderService;


    @ApiOperation(value = "根据试验台账id获取对应小票")
    @GetMapping("selectByExperimentId")
    public Json selectByExperimentId(@RequestParam("experimentId") Long experimentId, @RequestParam(value = "frwdh", required = false) Integer frwdh) {
        return Json.succ().data(experimentItemorderService.selectByExperimentId(experimentId, frwdh));
    }

    @ApiOperation(value = "删除试验委托和小票关系")
    @PostMapping(value = "deleteByExperimentIdAndItemorderId")
    public Json deleteByExperimentIdAndItemorderId(@RequestBody ExperimentItemorder entity) {
        Long experimentId = entity.getExperimentId();//试验委托id
        Integer itemorderId = entity.getItemorderId();//小票id
        assertTrue(experimentId == null, "试验委托id为空");
        assertTrue(itemorderId == null, "小票id为空");
        experimentItemorderService.deleteByExperimentIdAndItemorderId(experimentId, itemorderId);
        return Json.succ();
    }


}
